package io.renren.modules.app.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import io.renren.modules.app.annotation.Login;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.app.entity.TextManageEntity;
import io.renren.modules.app.service.TextManageService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;


/**
 * 文本管理表
 *
 * @date 2022-04-20 22:37:44
 */
@RestController
@RequestMapping("app/textmanage/")
public class TextManageController {
    @Autowired
    private TextManageService textManageService;

    /**
     * 列表
     */
    @RequestMapping("list")
    @RequiresPermissions("generator:textmanage:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = textManageService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("info/{textId}")
    @RequiresPermissions("generator:textmanage:info")
    public R info(@PathVariable("textId") Long textId) {
        TextManageEntity textManage = textManageService.getById(textId);

        return R.ok().put("textManage", textManage);
    }

    /**
     * 保存
     */
    @RequestMapping("save")
    @RequiresPermissions("generator:textmanage:save")
    public R save(@RequestBody TextManageEntity textManage) {
        textManage.setCreateTime(new Date());
        textManageService.save(textManage);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("update")
    @RequiresPermissions("generator:textmanage:update")
    public R update(@RequestBody TextManageEntity textManage) {
        textManageService.updateById(textManage);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("delete")
    @RequiresPermissions("generator:textmanage:delete")
    public R delete(@RequestBody Long[] textIds) {
        textManageService.removeByIds(Arrays.asList(textIds));

        return R.ok();
    }


    /**
     * 获取文本信息
     *
     * @param textId 文本id
     * @return
     */
    @Login
    @GetMapping("getTeacherById/{textId}")
    public R getTeacherById(@PathVariable("textId") Long textId) {
        TextManageEntity textManager = textManageService.getTextManagerById(textId);
        return R.ok().put("textManager", textManager);
    }

}
